package com.example.student.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.student.R;
import com.example.student.activity.AddTaskActivity;
import com.example.student.bean.TaskBean;
import com.example.student.myinterface.PopInterface;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

public class DoTaskAdapter extends RecyclerView.Adapter<DoTaskAdapter.ViewHolder> {

    private Context mContext;
    private List<TaskBean> mList;
    private PopInterface mPopInterface;
    private String TAG = "DoTaskAdapter";

    public DoTaskAdapter(Context context, List<TaskBean> list) {
        this.mContext = context;
        this.mList = list;

    }

    public DoTaskAdapter(Context context, PopInterface popInterface, List<TaskBean> list) {
        this.mContext = context;
        this.mList = list;
        this.mPopInterface = popInterface;

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_dotask_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(DoTaskAdapter.ViewHolder holder, int position) {

        TaskBean taskBean = mList.get(position);
        Log.e(TAG,"//mList.size():"+mList.size());
        Log.e(TAG,"//position:"+position);

        MyListener listener = new MyListener();

        for (int i = 0; i < mList.size(); i++) {
            View itemView = View.inflate(mContext, R.layout.item_dotask_subject, null);
            TextView tv_subject = (TextView) itemView.findViewById(R.id.tv_subject);
            TextView tv_finish = (TextView) itemView.findViewById(R.id.tv_finish);
            TextView tv_correct = (TextView) itemView.findViewById(R.id.tv_correct);
            TextView tv_nodo = itemView.findViewById(R.id.tv_nodo);
            tv_subject.setText("音乐");
            tv_finish.setText("已完成");
            tv_correct.setText("修改完了");
            tv_nodo.setText("没做");

//            tv_finish.setOnClickListener(listener);
//            tv_correct.setOnClickListener(listener);
//            tv_nodo.setOnClickListener(listener);

            tv_finish.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mPopInterface.setPopShow("finish");

                }
            });
            tv_correct.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e(TAG," 修改完了position:"+position);

                    mPopInterface.setPopShow("corrent");

                }
            });
            tv_nodo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.e(TAG," 不做position:"+position);

                }
            });

            holder.ll_item.addView(itemView);
        }

//        String subject = taskBean.getSubject();
//        Log.e(TAG,"//subject22222:"+subject);
//        if(!TextUtils.isEmpty(subject)){
//            holder.tv_subject.setText(subject);
//        }
//
//        String practice = taskBean.getPractice();
//        if(!TextUtils.isEmpty(practice)){
//            holder.tv_practice.setText(practice);
//        }
//        String practiceFinish = taskBean.getPractice_finish();
//        Log.e(TAG,"//practiceFinish:"+practiceFinish);
//        if(!TextUtils.isEmpty(practiceFinish)){
//            holder.tv_practice_finish.setText(practiceFinish);
//        }
//        String practiceCorrect = taskBean.getPractice_correct();
//        if(!TextUtils.isEmpty(practiceCorrect)){
//            holder.tv_practice_correct.setText(practiceCorrect);
//        }
//        String practiceNodo = taskBean.getPractice_nodo();
//        if(!TextUtils.isEmpty(practiceNodo)){
//            holder.tv_practice_nodo.setText(practiceNodo);
//        }



        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.e(TAG,"点击了");
                Intent in = new Intent(mContext, AddTaskActivity.class);
                Bundle bundle = new Bundle();
                TaskBean taskBean1 = mList.get(position);
                bundle.putSerializable( "doTask", (Serializable) taskBean1);
                in.putExtras(bundle);
                mContext.startActivity(in);
            }
        });



    }

    class MyListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.tv_finish:

                    Log.e("TAG","//..点击了完成");

                    break;
                case R.id.tv_correct:

                    Log.e("TAG","//..点击了批改");

                    break;
                case R.id.tv_nodo:

                    break;


            }

        }
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

//        private TextView tv_subject;
//        private TextView tv_practice,tv_practice_finish,tv_practice_correct,tv_practice_nodo;
//        private TextView tv_arithmetic,tv_arithmetic_finish,tv_arithmetic_correct,tv_arithmetic_nodo;
//        private TextView tv_preview,tv_preview_finish,tv_preview_correct,tv_preview_nodo;
        private LinearLayout ll_item;

        public ViewHolder(View itemView) {
            super(itemView);

            ll_item = itemView.findViewById(R.id.ll_item);
//            tv_subject = itemView.findViewById(R.id.tv_subject);
//            tv_practice = itemView.findViewById(R.id.tv_practice);
//            tv_practice_finish = itemView.findViewById(R.id.tv_practice_finish);
//            tv_practice_correct = itemView.findViewById(R.id.tv_practice_correct);
//            tv_practice_nodo = itemView.findViewById(R.id.tv_practice_nodo);
//
//            tv_arithmetic = itemView.findViewById(R.id.tv_arithmetic);
//            tv_arithmetic_finish = itemView.findViewById(R.id.tv_arithmetic_finish);
//            tv_arithmetic_correct = itemView.findViewById(R.id.tv_arithmetic_correct);
//            tv_arithmetic_nodo = itemView.findViewById(R.id.tv_arithmetic_nodo);


        }
    }



}
